package io.unicorn.modules.water.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import io.unicorn.common.utils.ExcelUtils;
import io.unicorn.common.validator.ValidatorUtils;
import io.unicorn.modules.water.entity.WaterdeptEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.unicorn.modules.water.entity.TDataErr2021Entity;
import io.unicorn.modules.water.service.TDataErr2021Service;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * ${comments}
 *
 * @author LNCG
 * @email LNCG@USTL.EDU.CN
 * @date 2021-05-21 20:36:24
 */
@RestController
@RequestMapping("water/tdataerr2021")
public class TDataErr2021Controller {
    @Autowired
    private TDataErr2021Service tDataErr2021Service;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("water:tdataerr2021:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tDataErr2021Service.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{dataMonth}")
    @RequiresPermissions("water:tdataerr2021:info")
    public R info(@PathVariable("dataMonth") String dataMonth){
        TDataErr2021Entity tDataErr2021 = tDataErr2021Service.getById(dataMonth);

        return R.ok().put("tDataErr2021", tDataErr2021);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("water:tdataerr2021:save")
    public R save(@RequestBody TDataErr2021Entity tDataErr2021){
        tDataErr2021Service.save(tDataErr2021);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("water:tdataerr2021:update")
    public R update(@RequestBody TDataErr2021Entity tDataErr2021){
        ValidatorUtils.validateEntity(tDataErr2021);
        tDataErr2021Service.updateById(tDataErr2021);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("water:tdataerr2021:delete")
    public R delete(@RequestBody String[] dataMonths){
        tDataErr2021Service.removeByIds(Arrays.asList(dataMonths));

        return R.ok();
    }

    @RequestMapping("/export")
    @RequiresPermissions("water:tclientinfo:list")
    public void export(@RequestParam Map<String, Object> params,
                       HttpServletRequest request,
                       HttpServletResponse repsonse){
        JSONObject jsonObject = JSONObject.parseObject((String)params.get("params"));
        PageUtils page = tDataErr2021Service.queryPage(jsonObject);
        List<?> listEntity = page.getList();

        ExcelUtils.exportXlsx(
                repsonse,
                "故障信息",
                "io.unicorn.modules.water.entity.TDataErr2021Entity",
                listEntity);
    }


    @RequestMapping("/queryArea")
    //@RequiresPermissions("sys:dept:list")
    public List<TDataErr2021Entity> queryArea(){
        List<TDataErr2021Entity> listRst = tDataErr2021Service.queryArea(new HashMap<String, Object>());

        return listRst;
    }

    @RequestMapping("/queryAreaUnit")
    //@RequiresPermissions("sys:dept:list")
    public List<TDataErr2021Entity> queryAreaUnit(@RequestParam Map<String, Object> params){
        List<TDataErr2021Entity> listRst = tDataErr2021Service.queryAreaUnit(params);

        return listRst;
    }

    @RequestMapping("/queryDebugger")
    //@RequiresPermissions("sys:dept:list")
    public List<TDataErr2021Entity> queryDebugger(@RequestParam Map<String, Object> params){
        List<TDataErr2021Entity> listRst = tDataErr2021Service.queryDebugger(params);

        return listRst;
    }

    @RequestMapping("/queryOverChart")
    //@RequiresPermissions("sys:dept:list")
    public List<Map<String, Object>> queryExceedChart(@RequestParam Map<String, Object> params){
       return tDataErr2021Service.queryExceedChart(params);
    }

    @RequestMapping("/queryYearChart")
    //@RequiresPermissions("sys:dept:list")
    public List<Map<String, Object>> queryYearChart(@RequestParam Map<String, Object> params){
        return tDataErr2021Service.queryYearChart(params);
    }
}
